using System;
using System.IO;
using System.Runtime.Serialization;
using EnvDTE;
using VSSDKAssist.Assets.References.Base;

namespace VSSDKAssist.Recipes.Common.References
{
	/// <summary>
	/// UnboundReference for a VSCT project item
	/// </summary>
	[Serializable]
	public class VSCTProjectItemReference : RecipeReferenceBase
	{
		/// <summary>
        /// Initializes a new instance of the <see cref="VSCTProjectItemReference"/> class.
		/// </summary>
		/// <param name="recipe">The recipe.</param>
		public VSCTProjectItemReference(string recipe)
			: base(recipe)
		{
		}

		/// <summary>
		/// See <see cref="P:Microsoft.Practices.RecipeFramework.IAssetReference.AppliesTo"/>.
		/// </summary>
		/// <value></value>
		public override string AppliesTo
		{
			get { return Properties.Resources.ResxProjectItemReference; }
		}

		/// <summary>
		/// Performs the validation of the item passed as target
		/// Returns true if the reference is allowed to be executed in the target
		/// that is if the target is a <see cref="ProjectItem"/> file.
		/// </summary>
		/// <param name="target"></param>
		/// <returns></returns>
		public override bool IsEnabledFor(object target)
		{
			ProjectItem item = target as ProjectItem;

			if(item != null)
			{
					return Path.GetExtension(item.Name).Equals(
						Properties.Resources.VSCTExtension,
						 StringComparison.OrdinalIgnoreCase);
			}
			return false;
		}

		#region ISerializable Members

		/// <summary>
		/// Initializes a new instance of the <see cref="T:ProjectItemReference"/> class.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the reference.</param>
		/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
		protected VSCTProjectItemReference(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
		}
		#endregion ISerializable Members
	}
}